<template>
    <div class="box2">
        <div class="item">{{title}}</div>
        <div class="list">
           <div :class="item.id == currentId ? 'actvice' : ''" v-for="item in data" :key="item.id" @click="changedItem(item.id)">
               <span>{{ item.name }}</span>
           </div>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return {
            currentId : null
        }
    },
    props:["title","data"],
    methods:{
        changedItem(id){
            this.currentId = id;
            this.$emit("changedItem",id);
        }
    },
    watch:{
        data(){
            this.currentId = this.data[0].id;
        }
    }
}
</script>

<style scoped>
.box2{
    margin: 10px;
    width: 100%;
    height: 80vh;
    background-color: #f4f4f4;
    padding: 10px;
    font-size: 14px;

}

.list{
    margin-top: 5px;
    width: 100%;
    background-color: white;
   
    

}
.list>div{
    line-height: 30px;
    padding-left: 20px;
}
.actvice{
    background-color: gray;
    color: white;
}
</style>